﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Class_KetNoi;

namespace GiaoDien
{
    public partial class uc_NhanVien : DevExpress.XtraEditors.XtraUserControl
    {
        public uc_NhanVien()
        {
            InitializeComponent();
        }
        KetNoi_NhanVien kn = new KetNoi_NhanVien();
        public void LoadDuLieu()
        {
            string sql = "select * from tbl_NhanVien";
            gridControl1.DataSource = kn.taobang(sql);
           
        }
        public void Nut()
        {
            btnthem.Enabled = false;
            btnsua.Enabled = false;
            btnxoa.Enabled = false;

            btnluu.Enabled = true;
            btnhuy.Enabled = true;
        }
        private void uc_NhanVien_Load(object sender, EventArgs e)
        {
            kn.connect();
            lbMaNhanVien.Hide();
            txtMaNhanVien.Hide();
            LoadDuLieu();
        }
        int flag;
        private void btnthem_Click(object sender, EventArgs e)
        {
            flag = 0;
            Nut();
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            flag = 1;
            Nut();
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            kn.xoa_NhanVien(txtMaNhanVien.Text.Trim());
            LoadDuLieu();
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            if (flag == 0)
            {
                kn.them_NhanVien(txtHoTen.Text ,cobGioiTinh.Text ,mskCMTND.Text,date_NgaySinh.Text ,txtNoiSinh.Text ,CobMaDanToc.Text,cobMaPhongBan.Text ,CobMaChucVu.Text ,mskSoDienThoai.Text ,txtHoKhau.Text ,txtChoOHienNay.Text ,date_NgayVaoLam.Text ,txtBHYT.Text ,txtATM.Text );
            }
            if (flag == 1)
            {
                kn.sua_NhanVien(txtMaNhanVien.Text ,txtHoTen.Text, cobGioiTinh.Text, mskCMTND.Text, date_NgaySinh.Text, txtNoiSinh.Text, CobMaDanToc.Text, cobMaPhongBan.Text, CobMaChucVu.Text, mskSoDienThoai.Text, txtHoKhau.Text, txtChoOHienNay.Text, date_NgayVaoLam.Text, txtBHYT.Text, txtATM.Text);
            }
            LoadDuLieu();
            btnthem.Enabled =true;
            btnsua.Enabled = true;
            btnxoa.Enabled = true;

            btnluu.Enabled = false;
            btnhuy.Enabled = false;
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            txtMaNhanVien.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaNV").ToString();
            txtHoTen.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"HoTen").ToString();
            cobGioiTinh.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"GioiTinh").ToString();
            mskCMTND.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"SoCMND").ToString();
            date_NgaySinh.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NgaySinh").ToString();
            txtNoiSinh.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NoiSinh").ToString();
            CobMaDanToc.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaDT").ToString();
            cobMaPhongBan.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaPB").ToString();
            CobMaChucVu.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"MaCV").ToString();
            mskSoDienThoai.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"DienThoai").ToString();
            txtHoKhau.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"HoKhau").ToString();
            txtChoOHienNay.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ChoOHienNay").ToString();
            date_NgayVaoLam.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"NgayVaoLam").ToString();
            txtBHYT.Text=gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"SoBHYT").ToString();
            txtATM.Text = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SoTheATM").ToString();
        }


    }
}
